package com.superzqb.asus.superzqbFragment.superzqbSave.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.superzqb.asus.superzqb.R;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by asus on 2017/4/21.
 */

public class SaveAdapter extends BaseAdapter{
    private ArrayList<Map<String,Object>> items;
    private Context context;
    public SaveAdapter(Context context, ArrayList<Map<String, Object>> lists){
        this.context=context;
        this.items=lists;
    }
    @Override
    public int getCount() {
        return items==null?0:items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void setList(ArrayList<Map<String, Object>> list){
        this.items=list;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.save_item,parent,false);
            convertView.setTag(new SaveAdapter.ViewHolder(convertView));
        }
        SaveAdapter.ViewHolder holder=(SaveAdapter.ViewHolder) convertView.getTag();
        Map<String,Object> map=items.get(position);
        holder.aimPrice.setText("目标金额(元) "+map.get("aimPrice").toString());
        holder.finishPrice.setText("已攒钱(元) "+map.get("finishPrice").toString());
        holder.aimFinish.setText("已完成目标"+map.get("aimFinish").toString()+"%");
        holder.finishTime.setText("还需要 "+map.get("finishTime").toString()+" 次攒钱");
        holder.must.setText("今日需存"+map.get("must").toString()+"(元)");
        return convertView;
    }


    class ViewHolder{
        private TextView aimPrice,finishPrice,aimFinish,finishTime,must;
        private ViewHolder(View view){
            aimPrice=(TextView)view.findViewById(R.id.aimPrice);
            finishPrice=(TextView)view.findViewById(R.id.finishPrice);
            aimFinish=(TextView)view.findViewById(R.id.aimFinish);
            finishTime=(TextView)view.findViewById(R.id.finishTime);
            must=(TextView)view.findViewById(R.id.must);

        }
    }
}
